date

executable=${6}

#some information about what is running:
cd /home/nucave/workdir/lattice/RENORMALIZATION/reno/NF2/Z4F/EXECUTABLES
echo "Working in: "
pwd
args=$(less args_${1})

Nmassm1=$(echo "$3-1" | bc -l)
Nrcm1=$(echo "$4-1" | bc -l)
twisted_basis=${5}

for imass in `seq 0 $Nmassm1`
do
for irc in `seq 0 $Nrcm1`
do


echo "Running:"
echo "time  ./${executable} ${args} -imom=${2} -imass=${imass} -irc=${irc} -twisted_basis=${twisted_basis}"


# run the program
time  ./${executable} ${args} -imom=${2} -imass=${imass} -irc=${irc} -twisted_basis=${twisted_basis}


done
done

echo " Program end! "

# delete the propagator 

# add node when finish

log=${7}
slot=${8}
nodes=${9}
echo "adding $slot to $nodes "

cd /home/nucave/workdir/lattice/RENORMALIZATION/reno/NF2/Z4F/SCRIPTS/Calc_D
pwd

echo "${slot}" >> ${nodes}

newstring="COMPLETED"
check_done=""
lockfile ${log}.lock
check_done=$(grep "In_progress" ${log} | grep ${slot})
if [[ -n ${check_done} ]]; then
      awk -v slot="$slot" -v newstring="$newstring" '{ if ($NF ~ /In_progress/ && $1 ~ slot) {sub("In_progress",newstring) ; print} else print}' ${log} >> ${log}.temp
      mv ${log}.temp ${log}
fi
rm -f ${log}.lock

lockfile ${nodes}.lock
rm -f ${nodes}.lock

date

